package com.abc.mapper;

import com.abc.entity.Ruzhi;
import com.abc.entity.User;
import com.abc.entity.Workers;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface UserMapper {
    /**
     * 根据用户名查询用户信息
     * @param username 用户名
     * @return User 查询到的用户信息
     */
    @Select("select * from user where username = #{username}")
    @Results(id = "userMap", value = {
            @Result(property = "id", column = "id", javaType = String.class,jdbcType = JdbcType.VARCHAR,id = true),
            @Result(property = "username", column = "username",javaType = String.class,jdbcType = JdbcType.VARCHAR),
            @Result(property = "password", column = "password",javaType = String.class,jdbcType = JdbcType.VARCHAR),
            @Result(property = "identity", column = "identity",javaType = String.class,jdbcType = JdbcType.VARCHAR),
            @Result(property = "isEnable", column = "is_enable",javaType = String.class,jdbcType = JdbcType.VARCHAR)})

    User selectByUsername(String username);
    @Insert("insert into user(username,password,identity,is_enable) values(#{username},#{password},#{identity},#{isEnable})")
    int insertUser(User user);
    @Select({"<script>",
            "SELECT * FROM workers",
            "WHERE 1=1",
            "<when test='name!=null and name!=\"\"'>",
            "AND name = #{name}",
            "</when>",
            "</script>"})
    List<Workers> list(String name);
    @Select({"<script>",
            "SELECT * FROM ruzhi",
            "WHERE 1=1",
            "<when test='name!=null and name!=\"\"'>",
            "AND gonghao like concat('%',#{gonghao},'%')",
            "</when>",
            "</script>"})
    List<Ruzhi> listRuzhi(String gonghao);
    @Select({"<script>",
            "SELECT * FROM workers ",
            " WHERE id = #{id}",
            "</script>"})
    Workers listById(String id);
    @Select({"<script>",
            "SELECT * FROM ruzhi ",
            " WHERE id = #{id}",
            "</script>"})
    Ruzhi listByIdRuzhi(String id);
    @Delete("delete from workers where id=#{id}")
    int deleteWorkers(String id);
    @Delete("delete from ruzhi where id=#{id}")
    int deleteRuzhi(String id);
    @Update("update workers set name=#{name},sex=#{sex},age=#{age},education=#{education},address=#{address},phone=#{phone} where id=#{id}")
    int updateWorkers(Workers workers);
    @Update("update ruzhi set gonghao=#{gonghao},bumen=#{bumen},zhiwu=#{zhiwu},ruzhishijian=#{ruzhishijian} where id=#{id}")
    int updateRuzhi(Ruzhi ruzhi);
    @Insert("insert into workers values (null,#{name},#{sex},#{age},#{education},#{address},#{phone})")
    int insertWorkers(Workers workers);
    @Insert("insert into ruzhi values (null,#{gonghao},#{bumen},#{zhiwu},#{ruzhishijian})")
    int insertRuzhi(Ruzhi ruzhi);
}
